#!/bin/bash

BINDIR=$(cd $(dirname $0) && pwd)

. ${BINDIR}/common
. ${BINDIR}/functions

cd ${FPPDIR}

logOutput

# Clear any restart flag
sed -i -e "s/^restartFlag .*/restartFlag = 0/" ${FPPHOME}/media/settings

if [ -f "/.dockerenv" ]
then
    /opt/fpp/scripts/fppd_stop
    /opt/fpp/scripts/fppd_start
else
    PID=$(pgrep -x fppd)
    if [ "x${PID}" == "x" ]
    then
        # fppd not running so we need to start
        systemctl start fppd
    else
        # kick running fppd to tell it to respawn
        systemctl reload fppd
    fi
fi
